﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["InHollandAir"] != null)
        {
            lbl_Aanmelden.Enabled = false;
            lbl_Aanmelden.Visible = false;
            lbl_Login.Enabled = false;
            lbl_Login.Visible = false;
        }

        else
        {
            lbl_GebruikerOverzicht.Enabled = false;
            lbl_GebruikerOverzicht.Visible = false;
            lbl_GebruikerWijzigen.Enabled = false;
            lbl_GebruikerWijzigen.Visible = false;
            btn_Uitloggen.Enabled = false;
            btn_Uitloggen.Visible = false;
        }
    }

    protected void btn_Uitloggen_Click1(object sender, EventArgs e)
    {
        verwijderSessie();
        Response.Cookies["InHollandAir"].Expires = DateTime.Now;
        Response.Redirect("Default.aspx");
    }

    private void verwijderSessie()
    {
        try
        {
            ConnectDB._Connection.Open();
            SqlCommand cmd;
            cmd = new SqlCommand(sp.setDeleteSessie, ConnectDB._Connection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter sessieId = cmd.Parameters.Add("@sessionid", SqlDbType.VarChar);

            sessieId.Value = Request.Cookies["InHollandAir"]["1"];

            cmd.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            LogError.writeToLogFile(ex.Message);
        }
        finally
        {
            ConnectDB._Connection.Close();
        }
    }
}
